package cn.edu.neusoft.wuguangsheng.flowerimpression.adapter;

import android.content.Context;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

import cn.edu.neusoft.wuguangsheng.flowerimpression.R;
import cn.edu.neusoft.wuguangsheng.flowerimpression.bean.GoodsBean;
import cn.edu.neusoft.wuguangsheng.flowerimpression.bean.SearchBean;

public class SearchAdapter extends BaseAdapter<SearchBean> {
    private List<GoodsBean> item;
    public SearchAdapter(Context context, List<SearchBean> items, int layoutResourse) {
        super(context, items, layoutResourse);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView= LayoutInflater.from(context).inflate(layoutResourse,parent,false);
        SearchViewHolder searchViewHolder = new SearchViewHolder(itemView);
        return searchViewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        SearchViewHolder searchViewHolder=(SearchViewHolder) holder;
        SearchBean searchBean=items.get(position);
        final String name = searchBean.getShop_name();
        searchViewHolder.searchitem_shopname.setText(name);


        LinearLayoutManager linearLayoutManager=new LinearLayoutManager(context);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        searchViewHolder.searchitem_rv.setLayoutManager(linearLayoutManager);
        item = searchBean.getGoodslist();
        GoodAdapter  goodAdapter = new GoodAdapter (context,item, R.layout.goods_item);
        //searchViewHolder.searchitem_rv.setAdapter(goodAdapter);
        searchViewHolder.searchitem_rv.setItemAnimator(new DefaultItemAnimator());
        searchViewHolder.searchitem_rv.setAdapter(goodAdapter);
    }
}
